import {expect} from "chai";
import { Quat } from "../src/Quat";
import { Mat3 } from "../src/Mat3";
import { Vec3 } from "../src/Vec3";
import { Euler } from "../src/Euler";
describe("Quat", function () {
    before(function() {
        console.log("开始自动化测试Quat...");
    });

    after(function() {
        console.log("结束...");
    });
    beforeEach(function() {
    });

    afterEach(function() {
    });
    it('#constructor', function () {
        let quat=new Quat([0,0,0,1]);
        expect(quat.equal([0,0,0,1])).to.equal(true);
    });
    it('#x', function () {
        let quat=new Quat([0,0,0,1]);
        expect(quat.x).to.equal(0);
    });
    it('#y', function () {
        let quat=new Quat([0,0,0,1]);
        expect(quat.y).to.equal(0);
    });
    it('#z', function () {
        let quat=new Quat([0,0,0,1]);
        expect(quat.z).to.equal(0);
    });
    it('#w', function () {
        let quat=new Quat([0,0,0,1]);
        expect(quat.w).to.equal(1);
    });
    it('#toString', function () {
        let quat=new Quat([0,0,0,1]);
        expect(quat.toString()).to.equal("Quat(0,0,0,1)");
    });
    it('#copy', function () {
        let q1=new Quat();
        let q2=new Quat([1,2,3,4]);
        q1.copy(q2)
        expect(q1.toString()).to.equal("Quat(1,2,3,4)");
    });
    it('#equal', function () {
        let q1=new Quat([1,2,3,4]);
        let q2=new Quat([1,2,3,4]);
        expect(q1.equal(q2)).to.equal(true);
    });
    it('#clone', function () {
        let q1=new Quat([1,2,3,4]);
        let q2=q1.clone();
        expect(q1.equal(q2)).to.equal(true);
    });
    it('#identity', function () {
        let q1=new Quat([1,2,3,4]);
        q1.identity();
        expect(q1.toString()).to.equal("Quat(0,0,0,1)");
    });
    it('#setAxisAngle', function () {
        let q1=new Quat();
        q1.setAxisAngle([0,0,1],Math.PI/3);
        expect(q1.equal([0,0,0.5,0.8660253882408142])).to.equal(true);
    });
    it('#getAxisAngle', function () {
        let q1=new Quat([0,0,0.5,0.8660253882408142]);
        let out=q1.getAxisAngle();
        expect(out.axis.equal([0,0,1])).to.equal(true);
    });
    it('#multiply', function () {
        let q1=new Quat([0,0,0.5,0.8660253882408142]);
        let q2=new Quat([0,0.3826834261417389,0,0.9238795042037964]);
        q1.multiply(q2);
        expect(q1.equal([-0.19134171307086945,0.3314135626977244,0.4619397521018982,0.8001031279563904])).to.equal(true);
    });
    it('#premultiply', function () {
        let q1=new Quat([0,0,0.5,0.8660253882408142]);
        let q2=new Quat([0,0.3826834261417389,0,0.9238795042037964]);
        q1.premultiply(q2);
        expect(q1.equal([0.19134171307086945,0.3314135670661926,0.4619397521018982,0.8001031279563904])).to.equal(true);
    });
    it('#rotateX', function () {
        let q1=new Quat([0,0,0.5,0.8660253882408142]);
        q1.rotateX(Math.PI/3);
        expect(q1.equal([0.4330126941204071,0.25,0.4330126941204071,0.75])).to.equal(true);
    });
    it('#rotateY', function () {
        let q1=new Quat([0,0,0.5,0.8660253882408142]);
        q1.rotateY(Math.PI/3);
        expect(q1.equal([-0.25,0.4330126941204071,0.4330126941204071,0.75])).to.equal(true);
    });
    it('#rotateZ', function () {
        let q1=new Quat([0,0,0.5,0.8660253882408142]);
        q1.rotateZ(Math.PI/3);
        expect(q1.equal([0,0,0.8660253882408142,0.5])).to.equal(true);
    });
    it('#calculateW', function () {
        let q1=new Quat([0,0,0.5,0.8660253882408142]);
        q1.calculateW();
        expect(q1.equal([0,0,0.5,0.8660253882408142])).to.equal(true);
    });
    it('#slerp', function () {
        let q1=new Quat([0,0,0.5,0.8660253882408142]);
        let q2=new Quat([0,0.3826834261417389,0,0.9238795042037964]);
        q1.slerp(q2,0.5);
        expect(q1.equal([0,0.2016860991716385,0.2635155916213989,0.9433357119560242])).to.equal(true);
    });
    it('#invert', function () {
        let q1=new Quat([0,0,0.5,0.8660253882408142]);
        q1.invert();
        expect(q1.equal([-0,-0,-0.5,0.8660253882408142])).to.equal(true);
    });
    it('#fromMat3', function () {
        let q1=new Quat();
        let mat3=new Mat3();
        mat3.fromRotation(Math.PI/3);
        q1.fromMat3(mat3);
        expect(q1.equal([0,0,0.5,0.8660253882408142])).to.equal(true);
    });
    it('#fromEuler', function () {
        let q1=new Quat();
        let euler=new Euler([1,2,3],"xyz")
        q1.fromEuler(euler);
        expect(q1.equal([0.7549338, -0.2061492, 0.5015091, -0.3688714])).to.equal(true);
    });
    it('#dot', function () {
        let q1=new Quat([0,0,0.5,0.8660253882408142]);
        let q2=new Quat([0,0.3826834261417389,0,0.9238795042037964]);
        let a=q1.dot(q2);        
        expect(a.toFixed(6)).to.equal('0.800103');
    });
    it('#normalize', function () {
        let q1=new Quat();
        q1.setAxisAngle([0,0,1],Math.PI/3);
        q1.normalize();   
        expect(q1.equal([0,0,0.5,0.8660253882408142])).to.equal(true);
    });
    it('#fromVector', function () {
        let v1=new Vec3([1,2,3]);
        let v2=new Vec3([-5,1,-2]);
        let q3=new Quat();
        q3.fromVector(v1,v2); 
        expect(q3.equal([0,-0.8320503234863281,0.5547001957893372,6.123234262925839e-17])).to.equal(true);
    });
})